package com.midea.thread;

public class TestRunnable {
    public static void main(String[] args) throws InterruptedException {
        Thread t1= new Thread(new TaskA());
        Thread t2= new Thread(new TaskB());
        t1.start();
        t2.start();

        //将该线程标记为守护线程（eg：垃圾回收线程），所有的非守护线程都结束时，进程就会结束。
        t2.setDaemon(true);
        /*
        //无期限等待，当前线程进入等待状态，直到t1线程中止，才会恢复执行
        t1.join();
        t2.join();
        System.out.println( Thread.currentThread().getName());
        System.out.println("All Thread is over");*/
    }
}
class TaskA implements Runnable {

    @Override
    public void run() {
        for (int i =0;i<=52;i++){
            System.out.println(i);
            System.out.println(Thread.currentThread().getName());
            //放弃CPU，回到就绪状态.
            Thread.yield();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class TaskB implements Runnable {

    @Override
    public void run() {
        for (char c = 'A';c<= 'Z';c++){
            System.out.println(c);
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}